package com.fourth_groups.shopping121store.ui.category.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.fourth_groups.shopping121store.R;

import java.util.ArrayList;
import java.util.List;


public class GoodsDetailRecycleAdapter extends RecyclerView.Adapter<GoodsDetailRecycleAdapter.MyViewHolder> {

    private List<String> imgUrlS = new ArrayList<>();
    private Context mContext;

    public GoodsDetailRecycleAdapter(Context context, List<String> details_img) {
        this.imgUrlS = details_img;
        this.mContext = context;
    }

    //规范的ViewHolder
    static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private ImageView ivItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            ivItem = (ImageView) itemView.findViewById(R.id.iv_item);
            ivItem.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {

        }
    }

    //创建ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_goods_detail, parent, false);
        return new MyViewHolder(view);
    }

    //绑定ViewHolder的数据.
    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        Glide.with(mContext).load(imgUrlS.get(position)).asBitmap().into(holder.ivItem);

    }

    @Override
    public int getItemCount() {

        return imgUrlS.size();
    }
}
